﻿//模块名称:描述该页面的名称
//功能描述:描述该模块的主要业务
//创建人:  
//创建时间:
//修改描述:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using webnew.Common;

namespace webnew.Systems
{
    /// <summary>
    /// 模板编辑页
    /// </summary>
    public partial class S_ChangePWD : WebPageBase.EditBase
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            _ListSrc = "~/Homepage.aspx";

            #region 隐藏母板页面按钮
            this.Master.FindControl("btnSaveBack").Visible = false;
            ((Button)this.Master.FindControl("btnSaveStay")).Text  = "保 存";
            this.Master.FindControl("btnBack").Visible = false;
            #endregion
            if (!IsPostBack)
            {
                SetTitle(true, "用户管理 >> 修改密码");
                
                if (UserInfor == null || UserInfor.Id == "")
                {
                    Response.Redirect("~/erropage.aspx?erro=1");
                }
            }
        }

        /// <summary>
        /// 重写基类验证数据方法
        /// </summary>
        protected override List<PageValid> _SetValidData()
        {

            List<PageValid> lst = new List<PageValid>();
            lst.Add(new PageValid("", "1", new BLL.Sys_User().ExistPwdRecord(UserInfor.Loginid, Common.CommonHelper.MyMd5(txtNewPwd.Text)), PageValid.validType.NoSameValid, "修改的密码不能与前5次相同"));
          
            return lst;
        }

        /// <summary>
        /// 重写基类保存数据方法
        /// </summary>
        protected override int SaveData()

        {
            //Common.md5(
            string OldPwd = Common.CommonHelper.MyMd5(txtOldPwd.Text);
            string NewPwd = Common.CommonHelper.MyMd5(txtNewPwd.Text);
            if (UserInfor != null && UserInfor.password  == OldPwd)
            {
                Model.Sys_UserInfo model = new Model.Sys_UserInfo();
                model.Loginid = UserInfor.Loginid;
                model.password = NewPwd;
                return new BLL.Sys_User().updatePwd(model); 
            }
            else
            {
                return 0;
            }
        }
    }
}
